Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making it easier to supply async http configuration. #274

Merged
merged 1 commit into from
Nov 13, 2017

Conversation

kiiadi
Copy link
Contributor

@kiiadi kiiadi commented Nov 8, 2017

Description

Instead of having to do this:

DynamoDBAsyncClient.builder().asyncHttpConfiguration(
    ClientAsyncHttpConfiguration.builder()
                                .httpClientFactory(NettySdkHttpClientFactory.builder()
                                                                            .maxConnectionsPerEndpoint(MAX_CONNECTIONS)
                                                                            .build())
                                .build())
                   .build();

we can do :

DynamoDBAsyncClient.builder().asyncHttpConfiguration(
    b -> b.httpClientFactory(NettySdkHttpClientFactory.builder()
                                                      .maxConnectionsPerEndpoint(MAX_CONNECTIONS)))
                           .build();

Copy link
Contributor

@shorea shorea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Would we have both means of configuring or pick just one?

@shorea
Copy link
Contributor

shorea commented Nov 8, 2017

We could also do something like the stepfunctions API and have a fluent factory class to reduce the verbosity.

public final class DynamoDbFluent {

   public static AttributeValue.Builder attributeValue();

   public static PutItemRequest.Builder putItemRequest();

}

@kiiadi
Copy link
Contributor Author

kiiadi commented Nov 8, 2017

I think they're both useful in different situations. The UnaryOperation one is when we can unambiguously determine the type, the SdkBuilder one is when we cannot (ie there's multiple implementations).

I also like the named static methods that will create a builder for you - that was actually in my original builder proposal way back when

*
* @see #asyncHttpConfiguration(ClientAsyncHttpConfiguration)
*/
default B asyncHttpConfiguration(UnaryOperator<ClientAsyncHttpConfiguration.Builder> asyncHttpConfiguration) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a Consumer to match builder's apply?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup - could be - I never liked that it mutated it, but that's the pattern we've followed before so it's probably better to remain consistent.

@millems
Copy link
Contributor

millems commented Nov 8, 2017

I've got to be honest:

DynamoDBAsyncClient.builder().asyncHttpConfiguration(
    b -> b.httpClientFactory(NettySdkHttpClientFactory.builder()
                                                      .maxConnectionsPerEndpoint(MAX_CONNECTIONS)))
                           .build();

This example is really hard to read. I can't really tell what it's doing the same way as the first.

I'm worried we're going overboard with these methods.

@millems
Copy link
Contributor

millems commented Nov 8, 2017

Also, I'm a bit confused why we don't have to call build() on the NettySdkHttpClientFactory.Builder? Didn't our usability studies say that people want to call .build()?

@kiiadi
Copy link
Contributor Author

kiiadi commented Nov 8, 2017

Definitely open to other suggestions here - this pattern makes sense to me, the IDE helps you a lot - I think there's similar patterns in languages like Kotlin/Scala so hopefully it's a pattern that's becoming more prevalent. We already use this pattern on our model object's copy method. However if there's confusion about how to use it among our team, then there's likely to be confusion more widely. As I see it we can solve this in one of two ways:

  1. A better pattern (as I say, open to suggestions here - this was the best I could come up with)
  2. Better documentation / examples

@kiiadi
Copy link
Contributor Author

kiiadi commented Nov 8, 2017

Also, I'm a bit confused why we don't have to call build() on the NettySdkHttpClientFactory.Builder? Didn't our usability studies say that people want to call .build()?

I didn't remember this specific piece of feedback. I suppose it's down to personal preference? In any case I don't think we'd take away the other methods, this just gives customers the option of omitting the build() call if they so choose.

@millems
Copy link
Contributor

millems commented Nov 8, 2017

Sorry to be that guy, but we need to talk about applying that (excluding build()) consistently across the SDK if we're going to add it here.

@kiiadi kiiadi force-pushed the kiiadi/better-builders branch from 8a3c974 to ee27b94 Compare November 13, 2017 20:36
@kiiadi
Copy link
Contributor Author

kiiadi commented Nov 13, 2017

Based on the feedback offline have removed the overload that takes a builder and calls build on behalf of the caller.

@kiiadi kiiadi merged commit de4d6fd into master Nov 13, 2017
@zoewangg zoewangg deleted the kiiadi/better-builders branch December 6, 2017 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants